export default {
  data() {
    return {
      userdata1: {
        username: '',
        password: '',
        email: '',
        phone: ''
      },
      nowpage: 1,
      total: 0,
      userdata: [],
      pagesizes: [2, 4, 6, 10],
      pagesize: 2,
      addUserVisible: false,
      adduserrules: {
        username: [{ required: true, message: '请输入用户名称', trigger: 'blur' }, { min: 3, max: 6, message: '长度在 3 到 6 个字符', trigger: 'blur' }],
        password: [{ required: true, message: '请输入登录密码', trigger: 'blur' }, { min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur' }],
        email: [{ required: true, message: '请输入邮箱', trigger: 'blur' }],
        phone: [{ required: true, message: '请输入电话', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.gituserdata()
  },
  methods: {
    async gituserdata() {
      const { data: res } = await this.$http.get('users', { params: { pagenum: this.nowpage, pagesize: this.pagesize } })
      this.userdata = res.data.users
      this.total = res.data.total
    },
    async addUser() {
      this.$refs.addUserFormRef.validate(async val => {
        if (!val) return this.$message.error('请填写正确的用户信息')
        const { data: res1 } = await this.$http.post('users', this.userdata1)
        if (res1.status === !200) return this.$message.error('添加用户失败')
        this.$message.success('添加用户成功')
        this.gituserdata()
      })
    },
    handleSizeChange(pafe) {
      this.pagesize = pafe
      this.gituserdata()
    },
    handleCurrentChange(page) {
      this.nowpage = page
      this.gituserdata()
    },
    userUpdata(scope) {
      console.log(scope.row)
    },
    userDelect() {
      console.log(2)
    }
  }
}
